import { ProFormOptions, FormItemProps } from '@/components/pro-form/type'
import { GridItemProps } from 'naive-ui'
import { WarehouseModel } from '@/api/model/sys/warehouse-model'
import { Ref } from 'vue'

type Props = {
  handleType: Ref<'add' | 'edit' | ''>
}

export const useWarehouseProForm = ({ handleType }: Props) => {
  const [warehouseForm, resetWarehouseForm] = useProRef<
    Partial<WarehouseModel>
  >({})
  const warehouseFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'warehouseName',
        label: '地址名称',
        placeholder: '请输入地址名称'
      },
      {
        formType: 'date',
        key: 'createdDate',
        label: '创建日期',
        placeholder: '请选择创建日期',
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true
      }
    ] as (FormItemProps & {
      gridItem?: GridItemProps
      noRule?: boolean
      ruleType?: string
    })[]
    return handleType.value === 'add'
      ? useSetOptions(list.filter((item) => !item?.disabled))
      : useSetOptions(list)
  })

  return {
    warehouseForm,
    warehouseFormOptions,
    resetWarehouseForm
  }
}
